//package com.itheima.ai.advisor;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.ai.chat.client.advisor.api.AdvisedRequest;
//import org.springframework.ai.chat.client.advisor.api.AdvisedResponse;
//import org.springframework.ai.chat.client.advisor.api.CallAroundAdvisor;
//import org.springframework.ai.chat.client.advisor.api.CallAroundAdvisorChain;
//import java.io.BufferedReader;
//import java.io.IOException;
//import java.io.InputStreamReader;
//import java.util.HashSet;
//import java.util.Set;
//
//public class ForbiddenWordsAdvisor implements CallAroundAdvisor {
//    private static final Logger log = LoggerFactory.getLogger(ForbiddenWordsAdvisor.class);
//    private final Set<String> forbiddenWordsSet;
//
//    public ForbiddenWordsAdvisor() {
//        this.forbiddenWordsSet = loadForbiddenWords();
//    }
//
//    private Set<String> loadForbiddenWords() {
//        Set<String> forbiddenWords = new HashSet<>();
//        try (BufferedReader reader = new BufferedReader(new InputStreamReader(
//                ForbiddenWordsAdvisor.class.getResourceAsStream("/forbidden-words.txt")))) {
//            String line;
//            while ((line = reader.readLine()) != null) {
//                line = line.trim();
//                if (!line.isEmpty() &&!line.startsWith("#")) {
//                    forbiddenWords.add(line);
//                }
//            }
//        } catch (IOException e) {
//            log.error("Error loading forbidden words file", e);
//        }
//        return forbiddenWords;
//    }
//
//    @Override
//    public AdvisedResponse aroundCall(AdvisedRequest advisedRequest, CallAroundAdvisorChain chain) {
//        String userText = advisedRequest.userText();
//        log.info("Checking for forbidden words in request: {}", userText);
//        for (String forbiddenWord : forbiddenWordsSet) {
//            if (userText.contains(forbiddenWord)) {
//                log.warn("Forbidden word '{}' found in request: {}", forbiddenWord, userText);
//                return createForbiddenWordDetectedResponse(forbiddenWord, userText);
//            }
//        }
//        return chain.next(advisedRequest);
//    }
//
//    private AdvisedResponse createForbiddenWordDetectedResponse(String detectedWord, String originalText) {
//        String errorMessage = String.format("抱歉，您的请求中包含不当词语“%s”，无法处理。", detectedWord);
//        return AdvisedResponse.builder()
//                .errorMessage(errorMessage)
//                .build();
//    }
//
//    @Override
//    public String getName() {
//        return "";
//    }
//
//    @Override
//    public int getOrder() {
//        return 0;
//    }
//}
